home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 312_01 / tlr2mak.awk < prev   
Text File  |  1990-04-21  |  15KB  |  343 lines

  1. #  HEADER:        ;
  2. #  TITLE:         Turbo Link Response file object file extractor
  3. #  DATE:          09/20/1989;
  4. #  VERSION:       1.2;
  5. #  DESCRIPTION:   "An AWK program which scans a link-configuration
  6. #                 file and builds a batch file which will in turn
  7. #                 produce a make-file.  Requires the services of a
  8. #                 source-file dependency generator (such as cincdep)."
  9. #  KEYWORDS:      Makefile, make, include, dependency generator;
  10. #  SYSTEM:        MS-DOS;
  11. #  WARNINGS:      "Filenames are assumed to contain only characters from
  12. #                 the limited set [A-Za-z_0-9.].  Your TLR file must
  13. #                 contain all of the object files which you want scanned
  14. #                 for dependencies, as well as the executable file name."
  15. #                 PolyAwk will generate false matches to lines
  16. #                 beginning with non-ASCII (i.e. 128..256) chars."
  17. #  FILENAME:      TLR2MAK.AWK;
  18. #  SEE-ALSO:      CINCDEP.AWK, CF2MAK.AWK, AINCDEP.AWK, PINCDEP.AWK;
  19. #  AUTHORS:       James Yehle;
  20. #  COMPILERS:     PolyAWK, Mortice Kern AWK, Rob Duff's PC-AWK 2.0;
  21. #
  22. #-----------------------------------------------------------------------------
  23. #
  24. #  TLR2mak.awk              Last modified  Sep 20, 1989  12:54
  25. #
  26. #     Scans an Turbo Link response file to produce a batch file for
  27. #     use with cincdep.awk to build a set of make-file dependency lists
  28. #
  29. #  Jim Yehle  753 Left Fork Rd. #B/Sugarloaf Star Route/Boulder, CO 80302 9252
  30. #
  31. # . . . Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . .
  32. #
  33. #       Sep 10 89  JRY  -- Released for C User's Group distribution --
  34. #  1.2  Sep 10 89  JRY  Added legal-filename-char regular expression
  35. #  1.1  Sep 8  89  JRY  Added "verbose" CO output as debug level 1.
  36. #  1.0  Aug 31 89  JRY  Initial creation.. adapted from Intel bind-
  37. #                        configuration file extractor CF2MAK.AWK (v 1.5).
  38. # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  39. #
  40. #  Usage is:
  41. #    awk -f tlr2mak.awk filename.tlr outfile=[path]filename
  42. #        lc=command lcf=[p][n][e] [>batchfile]
  43. #     where outfile gets the conglomerated dependency generator output
  44. #     Order of command-line parameters (save for "-f ..." 
  45. #      and ">batchfile") is irrelevant, but identifiers must be in lower case.
  46. #     lc is the compile command (no spaces allowed)
  47. #     lcf controls which components of the source file's name get
  48. #         included in the link command line: p = directory path,
  49. #         n = name, e = extension.
  50. # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  51. #
  52. #  Takes a Turbo Link response file as input.  Assumes that the portion of the
  53. #   TLINK command line containing the object file list and the executable file 
  54. #   is put into a "Turbo Link Response" file.  The linker must be invoked via a
  55. #   form such as "TLINK /c c0s @bawk.tlr,bawk.map,emu maths cs", where BAWK.TLR
  56. #   might contain "o:\bawk o:\bawkdo o:\bawkact o:\bawkpat o:\bawksym, o:\bawk".
  57. #   Alternatively, you could just put the whole business into BAWK.TLR and
  58. #   tell the linker "TLINK @bawk.tlr".
  59. #  Generates an executable-dependency list at the start of outfile,
  60. #   followed by the link command and the primary (executable) file name.
  61. #  Extracts all object file names.
  62. #  Generates a batch file line, for each object file found, of the form:
  63. #   comdpre srcfile "incpath="incpath "objname="file.obj
  64. #     "cc="cc "ccf="ccf comdmid outfile comdpost
  65. #  unless the source file can't be found, in which case it makes this line:
  66. #   comdpre "__NOFILE__ objname="file.obj "cc= ccf= " comdmid outfile comdpost
  67. #  The search for the source file covers C files only, but can be easily
  68. #   extended to support other languages. (See example in CF2MAK.AWK.)
  69. #
  70. #  Assumes object file names contain only these chars: [A-Za-z0-9_]*.obj
  71. # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  72. #
  73. # Turbo Link (response file) rules:
  74. #
  75. #  Lines can be continued by putting a '+' at the end of line
  76. #  Unterminated line is taken as a comma 
  77. #
  78. #  Turbo Link's command-line invocation form is:
  79. #   TLINK /options objfile objfile ..., exefile, mapfile, libfile libfile ... 
  80. #  Everything past TLINK can come from a response file, as in TLINK @exe.tlr
  81. #
  82. #-----------------------------------------------------------------------------
  83. #
  84. BEGIN {
  85.    #  Cf2mak supports several languages.  Each language must have
  86.    #   1) a source file name extension to replace object file extension (.obj)
  87.    #   2) a source directory pathname (stuck on front of file name during search)
  88.    #   3) an include-file directory whose name to pass to a dependency scanner
  89.    #   4) a compiler command to pass to dependency scanner (no spaces allowed)
  90.    #   5) controls for filename pathname/extension inclusion in compile command line
  91.    #   6) a dependency generator awk program
  92.  
  93.    # Language 1 is C
  94.    ext[1] = ".c"
  95.    path[1]    = "s:\\c\\"
  96.    ipath[1]   = "s:\\c\\inc\\"
  97.    cc[1] = "ccc"
  98.    ccf[1] = "n"
  99.    depgen[1] = "s:\\awk\\cincdep.awk"
  100.  
  101.    # Set various strings used in building batch-file command lines
  102.  
  103.    #    allpre      Leading line(s) of entire batch file
  104.    #    allpost     Trailing line(s) of entire batch file
  105.    #    comment     Comment-line lead-in: DOS "REM" or "ECHO", iRMX ";"
  106.    #    comdpre     Command line prefix
  107.    #    comdmid     Command line midle: between source & output file names
  108.    #    comdpost    Command line suffix
  109.    #    linecont    Line-continuation EOL char: snake " /", unix make "\"
  110.    #    fname_chars Regular expression specifying any single legal char
  111.    #                which can appear in a file name.  Must exclude 
  112.    #                directory path separator character! (DOS \, UNIX /)
  113.    allpre = "echo off"
  114.    allpost = "echo on"
  115.    comment = "echo "
  116.    comdpre = "awk -f "
  117.    comdmid = " >>"
  118.    comdpost = ""
  119.    linecont = " \\"
  120.    fname_chars = "[^\\\\ :]" # Unix "[^/ ]"; used to use "[A-Za-z0-9_]"
  121. #
  122.    co = "CON"   # Console-out: MS-DOS "CON", iRMX ":co:", unix "/dev/tty"
  123.    debug = 0    # 0=off, 1=verbose, 2=main-level debug, 3= adds functions
  124.  
  125.    print "tlr2mak.awk  Bind configuration object-file extractor  v 1.2" > co
  126.  
  127.    outfile = get_cl_param( "outfile=", 0)
  128.    lc = get_cl_param( "lc=", 0)
  129.    lcf = get_cl_param( "lcf=", 0)
  130.  
  131.    print allpre
  132.  
  133.    field = "objs"
  134.    field_end = 0
  135. }
  136. #
  137. {
  138.    gsub( /[\t]/, " ", $0) # Tabs -> spaces; re-parse $0
  139.  
  140.    # If line-continuer is glued to a fname, push it into next fname
  141.    sub( /\+$/, " +", $0) # (forces re-parsing of $0 into $1..$NF+1)
  142.    if (debug>1)
  143.       print "Line #" NR " has " NF " fnames:" >co
  144.    # Preserve NF, $1..$NF; since sub-functions' getline() will change them
  145.    nfnames = NF
  146.    for (f = 1; f <= NF; ++f) {
  147.       fname[f] = $f
  148.       if (debug>1)
  149.          print " -> fname[" f "] = '" $f "'." >co
  150.    }
  151.  
  152.    # Process each file name (i.e. word, or $1..$NF) in the line
  153.    for (f = 1; f <= nfnames; ++f) {
  154.       if (debug>1)
  155.          printf( "Processing fname[%d]: '%s'\n", f, fname[f]) >co
  156.       if (f==nfnames && fname[f]=="+") {
  157.          if (debug>1)
  158.             printf("Last fname[%d] == \"+\" (\"%s\")\n", f, fname[f]) >co
  159.          break
  160.       }  
  161.       if ( fname[f] ~ /^\// ) { # 1st char is '/':  its an /option
  162.          field_end = 0
  163.          if (debug>1)
  164.             print " ..it's an option." >co
  165.          continue
  166.       }
  167.       # If fname ends with a comma, remove it; stop after this fname
  168.       field_end = sub( /,$/, "", fname[f] )
  169.       if (field=="exe") { # Get executable-file name
  170.          # Split executable file name into Path, Name, and Extension components
  171.          split_filename( fname[f], exefile, fname_chars)
  172.          if (exefile["ext"]=="") { /* Turbo Link assumes ".EXE" extension
  173.             if (debug>1)
  174.                printf( " \".EXE\" added to executable-name \"%s\"\n",
  175.                        exefile["path"] exefile["name"]              ) >co
  176.             exefile["ext"]==".EXE")
  177.          }
  178.          if (debug>1) 
  179.